# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=imageio
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.24.0
pkgrel=1
pkgdesc="Python library for reading and writing a wide range of image, video, scientific, and volumetric data formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/imageio/imageio'
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-pillow")
optdepends=("${MINGW_PACKAGE_PREFIX}-freeimage: for FreeImage backend"
            "${MINGW_PACKAGE_PREFIX}-opencv: for OpenCV backend"
            "${MINGW_PACKAGE_PREFIX}-python-tifffile: for working with TIFF files")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::"${url}/archive/v${pkgver}.tar.gz")
sha256sums=('56fa82ca4b0eee7ee305e945c0b83c1f6640a11b27236ed9ab40e4818825923e')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python setup.py check --strict
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    "${MINGW_PREFIX}"/bin/python setup.py install --prefix="${MINGW_PREFIX}" \
      --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  # Remove utilities for downloading binary dependencies
  rm -rf "$pkgdir${MINGW_PREFIX}"/bin
}
